.class public Lcom/noshufou/android/su/widget/DateIndexer;
.super Ljava/lang/Object;
.source "DateIndexer.java"

# interfaces
.implements Landroid/widget/SectionIndexer;


# static fields
.field private static final TAG:Ljava/lang/String; = "Su.DateIndexer"


# instance fields
.field private mColumnIndex:I

.field private mCursor:Landroid/database/Cursor;

.field private mIntFormat:Ljava/text/SimpleDateFormat;

.field private mSectionCount:I

.field private mSectionDates:[I

.field private mSectionPositions:[I

.field private mSections:[Ljava/lang/String;


# direct methods
.method public constructor <init>(Landroid/content/Context;Landroid/database/Cursor;I)V
    .locals 12
    .parameter "context"
    .parameter "cursor"
    .parameter "sortedColumnIndex"

    .prologue
    const/4 v11, -0x1

    .line 24
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 25
    iput-object p2, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    .line 26
    iput p3, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mColumnIndex:I

    .line 27
    new-instance v8, Ljava/text/SimpleDateFormat;

    const-string v9, "yyyyDDD"

    invoke-direct {v8, v9}, Ljava/text/SimpleDateFormat;-><init>(Ljava/lang/String;)V

    iput-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mIntFormat:Ljava/text/SimpleDateFormat;

    .line 28
    new-instance v0, Ljava/util/GregorianCalendar;

    invoke-direct {v0}, Ljava/util/GregorianCalendar;-><init>()V

    .line 30
    .local v0, calendar:Ljava/util/GregorianCalendar;
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    invoke-interface {v8}, Landroid/database/Cursor;->moveToFirst()Z

    .line 31
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    iget v9, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mColumnIndex:I

    invoke-interface {v8, v9}, Landroid/database/Cursor;->getLong(I)J

    move-result-wide v2

    .line 32
    .local v2, firstDateLong:J
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    invoke-interface {v8}, Landroid/database/Cursor;->moveToLast()Z

    .line 33
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    iget v9, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mColumnIndex:I

    invoke-interface {v8, v9}, Landroid/database/Cursor;->getLong(I)J

    move-result-wide v6

    .line 35
    .local v6, lastDateLong:J
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mIntFormat:Ljava/text/SimpleDateFormat;

    invoke-static {v2, v3}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v9

    invoke-virtual {v8, v9}, Ljava/text/SimpleDateFormat;->format(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v8

    invoke-static {v8}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v1

    .line 36
    .local v1, firstDateInt:I
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mIntFormat:Ljava/text/SimpleDateFormat;

    invoke-static {v6, v7}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v9

    invoke-virtual {v8, v9}, Ljava/text/SimpleDateFormat;->format(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v8

    invoke-static {v8}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v5

    .line 37
    .local v5, lastDateInt:I
    sub-int v8, v1, v5

    add-int/lit8 v8, v8, 0x1

    iput v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionCount:I

    .line 39
    iget v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionCount:I

    new-array v8, v8, [Ljava/lang/String;

    iput-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSections:[Ljava/lang/String;

    .line 40
    iget v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionCount:I

    new-array v8, v8, [I

    iput-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionDates:[I

    .line 41
    iget v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionCount:I

    new-array v8, v8, [I

    iput-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionPositions:[I

    .line 43
    invoke-virtual {v0, v2, v3}, Ljava/util/GregorianCalendar;->setTimeInMillis(J)V

    .line 44
    const/4 v4, 0x0

    .local v4, i:I
    :goto_0
    iget v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionCount:I

    if-lt v4, v8, :cond_0

    .line 50
    return-void

    .line 45
    :cond_0
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSections:[Ljava/lang/String;

    invoke-virtual {v0}, Ljava/util/GregorianCalendar;->getTimeInMillis()J

    move-result-wide v9

    invoke-static {p1, v9, v10}, Lcom/noshufou/android/su/util/Util;->formatDate(Landroid/content/Context;J)Ljava/lang/String;

    move-result-object v9

    aput-object v9, v8, v4

    .line 46
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionDates:[I

    iget-object v9, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mIntFormat:Ljava/text/SimpleDateFormat;

    invoke-virtual {v0}, Ljava/util/GregorianCalendar;->getTime()Ljava/util/Date;

    move-result-object v10

    invoke-virtual {v9, v10}, Ljava/text/SimpleDateFormat;->format(Ljava/util/Date;)Ljava/lang/String;

    move-result-object v9

    invoke-static {v9}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v9

    aput v9, v8, v4

    .line 47
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionPositions:[I

    aput v11, v8, v4

    .line 48
    const/4 v8, 0x5

    invoke-virtual {v0, v8, v11}, Ljava/util/GregorianCalendar;->add(II)V

    .line 44
    add-int/lit8 v4, v4, 0x1

    goto :goto_0
.end method


# virtual methods
.method public getPositionForSection(I)I
    .locals 10
    .parameter "section"

    .prologue
    const/4 v7, 0x0

    .line 54
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    if-nez v8, :cond_0

    move v4, v7

    .line 95
    :goto_0
    return v4

    .line 58
    :cond_0
    if-gtz p1, :cond_1

    move v4, v7

    .line 59
    goto :goto_0

    .line 62
    :cond_1
    iget v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionCount:I

    if-lt p1, v8, :cond_2

    .line 63
    iget-object v7, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    invoke-interface {v7}, Landroid/database/Cursor;->getCount()I

    move-result v4

    goto :goto_0

    .line 66
    :cond_2
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionPositions:[I

    aget v8, v8, p1

    if-lez v8, :cond_3

    .line 67
    iget-object v7, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionPositions:[I

    aget v4, v7, p1

    goto :goto_0

    .line 70
    :cond_3
    const/4 v6, 0x0

    .line 71
    .local v6, start:I
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    invoke-interface {v8}, Landroid/database/Cursor;->getCount()I

    move-result v3

    .line 73
    .local v3, end:I
    add-int/lit8 v4, p1, -0x1

    .local v4, i:I
    :goto_1
    if-gtz v4, :cond_4

    .line 80
    :goto_2
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    invoke-interface {v8}, Landroid/database/Cursor;->getPosition()I

    move-result v5

    .line 83
    .local v5, savedCursorPos:I
    move v4, v6

    :goto_3
    if-lt v4, v3, :cond_6

    .line 93
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    invoke-interface {v8, v5}, Landroid/database/Cursor;->moveToPosition(I)Z

    move v4, v7

    .line 95
    goto :goto_0

    .line 74
    .end local v5           #savedCursorPos:I
    :cond_4
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionPositions:[I

    aget v8, v8, v4

    if-lez v8, :cond_5

    .line 75
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionPositions:[I

    aget v6, v8, v4

    .line 76
    goto :goto_2

    .line 73
    :cond_5
    add-int/lit8 v4, v4, -0x1

    goto :goto_1

    .line 84
    .restart local v5       #savedCursorPos:I
    :cond_6
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    invoke-interface {v8, v4}, Landroid/database/Cursor;->moveToPosition(I)Z

    move-result v8

    if-eqz v8, :cond_7

    .line 85
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    iget v9, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mColumnIndex:I

    invoke-interface {v8, v9}, Landroid/database/Cursor;->getLong(I)J

    move-result-wide v0

    .line 86
    .local v0, date:J
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mIntFormat:Ljava/text/SimpleDateFormat;

    invoke-static {v0, v1}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v9

    invoke-virtual {v8, v9}, Ljava/text/SimpleDateFormat;->format(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v8

    invoke-static {v8}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v2

    .line 87
    .local v2, dateInt:I
    iget-object v8, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionDates:[I

    aget v8, v8, p1

    if-lt v8, v2, :cond_7

    .line 88
    iget-object v7, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionPositions:[I

    aput v4, v7, p1

    goto :goto_0

    .line 83
    .end local v0           #date:J
    .end local v2           #dateInt:I
    :cond_7
    add-int/lit8 v4, v4, 0x1

    goto :goto_3
.end method

.method public getSectionForPosition(I)I
    .locals 8
    .parameter "position"

    .prologue
    .line 100
    iget-object v5, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    invoke-interface {v5}, Landroid/database/Cursor;->getPosition()I

    move-result v4

    .line 101
    .local v4, savedCursorPos:I
    iget-object v5, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    invoke-interface {v5, p1}, Landroid/database/Cursor;->moveToPosition(I)Z

    .line 102
    iget-object v5, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    iget v6, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mColumnIndex:I

    invoke-interface {v5, v6}, Landroid/database/Cursor;->getLong(I)J

    move-result-wide v0

    .line 103
    .local v0, date:J
    iget-object v5, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mCursor:Landroid/database/Cursor;

    invoke-interface {v5, v4}, Landroid/database/Cursor;->moveToPosition(I)Z

    .line 104
    iget-object v5, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mIntFormat:Ljava/text/SimpleDateFormat;

    invoke-static {v0, v1}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v6

    invoke-virtual {v5, v6}, Ljava/text/SimpleDateFormat;->format(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v5

    invoke-static {v5}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v2

    .line 107
    .local v2, dateInt:I
    const/4 v3, 0x0

    .local v3, i:I
    :goto_0
    iget v5, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionCount:I

    if-lt v3, v5, :cond_1

    .line 113
    const-string v5, "Su.DateIndexer"

    new-instance v6, Ljava/lang/StringBuilder;

    const-string v7, "Section not found for date "

    invoke-direct {v6, v7}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v6, v2}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    invoke-static {v5, v6}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 114
    const/4 v3, 0x0

    .end local v3           #i:I
    :cond_0
    return v3

    .line 108
    .restart local v3       #i:I
    :cond_1
    iget-object v5, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSectionDates:[I

    aget v5, v5, v3

    if-eq v2, v5, :cond_0

    .line 107
    add-int/lit8 v3, v3, 0x1

    goto :goto_0
.end method

.method public getSections()[Ljava/lang/Object;
    .locals 1

    .prologue
    .line 119
    iget-object v0, p0, Lcom/noshufou/android/su/widget/DateIndexer;->mSections:[Ljava/lang/String;

    return-object v0
.end method
